{{define "title"}}GCTT 文章发布 - Go中文翻译组 {{end}}
{{define "content"}}
<div class="row">
    <div class="col-md-9 col-sm-6">
        <div class="sep20"></div>
        <ol class="breadcrumb">
            <li><a href="/">首页</a></li>
            <li><a href="/gctt">GCTT</a></li>
            <li class="active">发文章</li>
        </ol>
        <div class="page box_white">
            <form class="form-horizontal validate-form" role="form" action="/gctt-new" data-redirect="/articles?r={{timestamp}}">
            {{if .gctt_user.Id}}
                <input type="hidden" name="markdown" value="1">
                <input type="hidden" name="gctt" value="1">
                <textarea id="txt" name="txt" style="display: none;"></textarea>
                <textarea id="content" name="content" style="display: none;"></textarea>
                <div class="form-group form-group-sm">
                    <label class="col-sm-1 control-label" for="title"><abbr>*</abbr>标题</label>
                    <div class="col-sm-11">
                        <input class="form-control required" type="text" id="title" name="title" placeholder="标题">
                    </div>
                </div>
                <div class="form-group form-group-sm">
                    <label class="col-sm-1 control-label" for="title">封面</label>
                    <div class="col-sm-11">
                        <input class="form-control" type="text" id="cover" name="cover" placeholder="封面">
                    </div>
                </div>
                <div class="form-group form-group-sm">
                    <label class="col-sm-1 control-label"><abbr>*</abbr>作者</label>
                    <div class="col-sm-11">
                        <div class="row">
                            <div class="col-sm-3">
                                <input class="form-control required" type="text" id="author" name="author" placeholder="原作者">
                            </div>
                            <div class="col-sm-9">
                                <input class="form-control required" type="text" id="author-url" name="author_url" placeholder="作者链接">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="form-group form-group-sm">
                    <label class="col-sm-1 control-label"><abbr>*</abbr>译者</label>
                    <div class="col-sm-11">
                        <div class="row">
                            <div class="col-sm-5">
                                <input class="form-control required" type="text" id="translator" name="translator" placeholder="GCTT 译者 GitHub ID">
                            </div>
                            <label class="col-sm-1 control-label"><abbr>*</abbr>校对</label>
                            <div class="col-sm-6">
                                <input class="form-control required" type="text" id="checker" name="checker" placeholder="GCTT 校对者 GitHub ID，多个逗号分隔">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="form-group form-group-sm">
                    <label class="col-sm-1 control-label"><abbr>*</abbr>原文</label>
                    <div class="col-sm-11">
                        <input class="form-control required" type="text" id="url" name="url" placeholder="原文链接">
                    </div>
                </div>
                <div class="form-group form-group-sm" id="markdown-editor">
                    <label class="col-sm-1 control-label" for="content"><abbr>*</abbr>正文</label>
                    <div class="col-sm-11">
                        <div class="row clearfix md-toolbar">
                            <ul class="col-md-10 list-inline">
                                <li class="edit cur"><a href="#" tabindex="-1"><i class="glyphicon glyphicon-edit"></i> 编辑</a></li>
                                <li class="preview"><a href="#" title="预览" tabindex="-1"><i class="glyphicon glyphicon-eye-open preview"></i> 预览</a></li>
                            </ul>
                            <div class="col-md-2 text-right">
                                <i id="upload-img" class="glyphicon glyphicon-picture upload-img tool-tip" data-toggle="tooltip" data-placement="top" title="上传图片"></i>
                            </div>
                        </div>
                        <textarea class="form-control need-autogrow main-textarea" id="markdown-content" name="markdown-content" rows="15" tabindex="0"></textarea>
                        <div class="content-preview markdown-body"></div>
                    </div>
                </div>

                <div class="form-group form-group-sm">
                    <label class="col-sm-5 control-label">&nbsp;</label>
                    <div class="col-sm-6">
                        <button type="submit" class="btn btn-default btn-sm" id="submit">发布文章</button> (Ctrl+Enter)
                    </div>
                </div>

                <div class="form-group form-group-sm markdown-preview">
                    <label class="col-sm-1 control-label">预览</label>
                    <div class="col-sm-11">
                        <div id="content-preview" style="border: 1px solid #ccc; padding: 5px; font-size: 13px;" class="markdown-body"></div>
                    </div>
                </div>
            {{else}}
                <div class="text-center">
                    <div class="sep20"></div>
                    <div>
                        <span class="alert alert-warning">您没有权限发布译文，请先成为译者</span>
                    </div>
                    <div class="sep20"></div>
                    <div>
                        <a class="btn btn-default btn-sm" href="/gctt-apply">申请成为译者</a>
                    </div>
                </div>
                <div class="sep10"></div>
            {{end}}

            </form>
        </div>
    </div>
    <div class="col-md-3 col-sm-6">
        <div class="sep20"></div>
        
        <div class="box_white sidebar sb-author">
            <div class="top">
                <h3 class="title"><i class="glyphicon glyphicon-list-alt"></i>&nbsp;发布文章说明</h3>
            </div>
            <div class="sb-content">
                <span class="help-block">
                    <ul class="markdown-help">
                        <li>支持 Markdown 格式, <strong>**粗体**</strong>、~~删除线~~、<code>`单行代码`</code></li>
                        <li>http://example.org 自动加链接</li>
                        <li>代码支持高亮，如：```go func main() {}``` 则是Go语法高亮</li>
                        <li><strong>@name</strong> 会链接到用户页面，并会通知他</li>
                        <li>![alt 文本](http://foo.com/bar.jpg) 显示图片</li>
                        <li>:smile: 支持 <strong>emoji 表情</strong>，见<a href="http://www.emoji-cheat-sheet.com/" target="_blank">Emoji cheat sheet</a></li>
                        <li>完整 Markdwon 语法说明：<a href="http://wowubuntu.com/markdown/" target="_blank">语法说明 (简体中文版)</a></li>
                    </ul>
                </span>
            </div>
        </div>

    </div>
</div>
{{end}}
{{define "css"}}
{{include "cssjs/prism.css.html" .}}
{{end}}
{{define "js"}}

{{include "cssjs/publish.js.html" .}}
{{include "cssjs/prism.js.html" .}}

<script>

var isNew = isMarkdown = true;

var cacheKey = 'gctt';

$(function() {
    // 文本框自动伸缩
    $('.need-autogrow').autoGrow();

    function saveArticleComposeDraft() {
        var title = $('#title').val(),
            content = $('#markdown-content').val(),
            author = $('#author').val(),
            authorURL = $('#author-url').val(),
            translator = $('#translator').val(),
            checker = $('#checker').val(),
            url = $('#url').val();

        var objdata = {title: title, content: content,
            author: author, author_url: authorURL,
            translator: translator, checker: checker, url: url};

        saveComposeDraft(uid, cacheKey, objdata);
    }

    (function() {
        if (isNew && isMarkdown) {
            var draft = loadComposeDraft(uid, cacheKey);
            if (draft) {
                $('#title').val(draft.title);
                $('#markdown-content').val(draft.content);
                $('#author').val(draft.author);
                $('#author-url').val(draft.author_url);
                $('#translator').val(draft.translator);
                $('#checker').val(draft.checker),
                $('#url').val(draft.url);
            }

            $('.need-autogrow').autoGrow();
        }
    })();

    $('#title,#markdown-content,#author,#author-url,#translator,#checker,#url').on('change', function() {
        saveArticleComposeDraft();
    });
});
</script>
<script type="text/javascript" src="{{.static_domain}}/static/dist/js/articles.min.js"></script>
{{end}}